﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Dosimetria.Models;
using Dosimetria.Models.DataAnnotations_Classes;
using Dosimetria.DAL;

namespace Dosimetria.Controllers
{ 
    public class SistemaController : Controller
    {
        private Querys db = new Querys();

        //
        // GET: /Sistema/

        public ViewResult Index()
        {
            return View(db.getListOfSistemas());
        }

        //
        // GET: /Sistema/Details/5

        public ViewResult Details(int id)
        {
            Sistema s = db.getSistemaById(id);
            return View(s);
        }

        //
        // GET: /Sistema/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Sistema/Create

        [HttpPost]
        public ActionResult Create(Sistema sistemas)
        {
            if (ModelState.IsValid)
            {
                db.createSistema(sistemas);
                return RedirectToAction("Index");  
            }

            return View(sistemas);
        }
        
        //
        // GET: /Sistema/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View(db.getSistemaById(id));
        }

        //
        // POST: /Sistema/Edit/5

        [HttpPost]
        public ActionResult Edit(Sistema sistemas)
        {
            if (ModelState.IsValid)
            {
                db.changeStateSistema(sistemas);
                return RedirectToAction("Index");
            }
            return View(sistemas);
        }

        //
        // GET: /Sistema/Delete/5
 
        public ActionResult Delete(int id)
        {
            Sistema s = db.getSistemaById(id);
            return View(s);
        }

        //
        // POST: /Sistema/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            db.deleteSistemaByid(id);
            return RedirectToAction("Index");
        }

        //protected override void Dispose(bool disposing)
        //{
        //    db.Dispose();
        //    base.Dispose(disposing);
        //}
    }
}